public class Solution_108 {
    
    public TreeNode sortedArrayToBST(int[] nums) {
        return insertHelper(nums, 0, nums.length - 1);
    }

    public TreeNode insertHelper(int[] nums, int left, int right) {
        if (left > right) return null;
        int mid = (left + right) / 2;

        TreeNode root = new TreeNode(nums[mid]);
        root.left = insertHelper(nums, left, mid - 1);
        root.right = insertHelper(nums, mid + 1, right);

        return root;
    }


    public static void main(String[] args) {
        int[] nums = {-10,-3,0,5,9};
        TreeNode root = new Solution_108().sortedArrayToBST(nums);
        System.out.println(root.toString());
    }

}
